package com.hnkywl.sts.dao.djgl;

import com.hnkywl.sts.entity.djgl.Glfyx;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.hibernate.Criteria;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-5-2
 * Time: 下午5:25
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class GlfyxDao extends SimpleHibernateTemplate<Glfyx, Long> {

    public List<Map> findCgfyx(Long id) {
        Criteria criteria = getSession().createCriteria(Glfyx.class)
                .createAlias("sydw", "sydw", CriteriaSpecification.LEFT_JOIN)
                .createAlias("fylb", "fylb", CriteriaSpecification.LEFT_JOIN)
                .createAlias("wljsd", "jsd", CriteriaSpecification.LEFT_JOIN)
                .setProjection(Projections.projectionList()
                        .add(Property.forName("sydw.id").as("sydw.id"))
                        .add(Property.forName("sydw.qc").as("sydw.qc"))
                        .add(Property.forName("fylb.id").as("fylb.id"))
                        .add(Property.forName("fylb.fykmjc").as("fylb.fykmjc"))
                        .add(Property.forName("jfsl").as("jfsl"))
                        .add(Property.forName("dj").as("dj"))
                        .add(Property.forName("je").as("je"))
                        .add(Property.forName("jsd.jsdh").as("jsdh"))
                        .add(Property.forName("bz").as("bz"))
                ).add(Restrictions.eq("cgd.id", id))
                .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
        return (List<Map>) criteria.list();
    }

}
